/*     */ package com.wgcloud.controller;
/*     */

import cn.hutool.json.JSONUtil;
import com.github.pagehelper.PageInfo;
import com.wgcloud.config.CommonConfig;
import com.wgcloud.dto.ChartInfo;
import com.wgcloud.entity.CpuTemperatures;
import com.wgcloud.entity.SystemInfo;
import com.wgcloud.service.*;
import com.wgcloud.util.FormatUtil;
import com.wgcloud.util.HostUtil;
import com.wgcloud.util.ThreadPoolUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"/daping"})
/*     */ public class DapingCotroller {
/*     */   private void testThread() {
/*  44 */     Runnable runnable = () -> logger.info("DapingCotroller----------testThread");
/*     */ 
/*     */     
/*  47 */     ThreadPoolUtil.executor.execute(runnable);
/*     */   }
/*     */ 
/*     */   
/*  51 */   private static final Logger logger = LoggerFactory.getLogger(com.wgcloud.controller.DapingCotroller.class);
/*     */   
/*     */   @Resource
/*     */   DbTableService dbTableService;
/*     */   
/*     */   @Resource
/*     */   PortInfoService portInfoService;
/*     */   
/*     */   @Resource
/*     */   DbInfoService dbInfoService;
/*     */   
/*     */   @Resource
/*     */   SystemInfoService systemInfoService;
/*     */   
/*     */   @Resource
/*     */   AppInfoService appInfoService;
/*     */   
/*     */   @Resource
/*     */   FileWarnInfoService fileWarnInfoService;
/*     */   
/*     */   @Resource
/*     */   FileWarnStateService fileWarnStateService;
/*     */   
/*     */   @Resource
/*     */   DockerInfoService dockerInfoService;
/*     */   
/*     */   @Resource
/*     */   LogInfoService logInfoService;
/*     */   
/*     */   @Autowired
/*     */   HeathMonitorService heathMonitorService;
/*     */   @Autowired
/*     */ HostGroupService hostInfoService;
/*     */   @Autowired
/*     */   CpuStateService cpuStateService;
/*     */   @Autowired
/*     */   MemStateService memStateService;
/*     */   @Autowired
/*     */   SysLoadStateService sysLoadStateService;
/*     */   @Autowired
/*     */   NetIoStateService netIoStateService;
/*     */   @Autowired
/*     */   DeskStateService deskStateService;
/*     */   @Autowired
/*     */   DeskIoService deskIoService;
/*     */   @Autowired
/*     */   TaskUtilService taskUtilService;
/*     */   @Resource
/*     */   CpuTemperaturesService cpuTemperaturesService;
/*     */   @Autowired
/*     */   CommonConfig commonConfig;
/*     */   
/*     */   @RequestMapping({"index"})
/*     */   public String index(Model model, HttpServletRequest request) {
/* 105 */     Map<String, Object> params = new HashMap<>();
/*     */     try {
/* 107 */       List<SystemInfo> systemInfoList = this.systemInfoService.selectAllByParams(params);
/*     */ 
/*     */       
/* 110 */       List<ChartInfo> systemInfoTypeList = HostUtil.getSystemTypeList(systemInfoList);
/* 111 */       List<String> systemInfoTypeNameList = new ArrayList<>();
/* 112 */       List<Integer> systemInfoTypeValList = new ArrayList<>();
/* 113 */       for (ChartInfo chartInfo : systemInfoTypeList) {
/* 114 */         systemInfoTypeNameList.add(chartInfo.getItem());
/* 115 */         systemInfoTypeValList.add(chartInfo.getCount());
/*     */       } 
/* 117 */       model.addAttribute("systemInfoTypeNameList", JSONUtil.parseArray(systemInfoTypeNameList));
/* 118 */       model.addAttribute("systemInfoTypeValList", JSONUtil.parseArray(systemInfoTypeValList));
/*     */ 
/*     */ 
/*     */       
/* 122 */       int totalSystemInfoSize = this.systemInfoService.countByParams(params);
/* 123 */       model.addAttribute("totalSystemInfoSize", Integer.valueOf(totalSystemInfoSize));
/*     */ 
/*     */       
/* 126 */       params.clear();
/* 127 */       params.put("state", "2");
/* 128 */       int hostDownSize = this.systemInfoService.countByParams(params);
/* 129 */       model.addAttribute("hostDownSize", Integer.valueOf(hostDownSize));
/*     */ 
/*     */       
/* 132 */       setSysPie(model);
/*     */       
/* 134 */       cpuTop10(model);
/* 135 */       memTop10(model);
/*     */       
/* 137 */       setMiddleData(systemInfoList, model);
/*     */       
/* 139 */       bytesTop10(model);
/*     */       
/* 141 */       warnInfoInit(model);
/*     */       
/* 143 */       return "daping/index";
/* 144 */     } catch (Exception e) {
/* 145 */       logger.error("大屏展示错误", e);
/*     */       
/* 147 */       return "";
/*     */     } 
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   private void setSysPie(Model model) throws Exception {
/* 157 */     Map<String, Object> params = new HashMap<>();
/* 158 */     int totalSystemInfoSize = this.systemInfoService.countByParams(params);
/* 159 */     params.put("state", "2");
/* 160 */     int hostDownSize = this.systemInfoService.countByParams(params);
/* 161 */     model.addAttribute("hostDownSize", Integer.valueOf(hostDownSize));
/* 162 */     model.addAttribute("hostOnSize", Integer.valueOf(totalSystemInfoSize - hostDownSize));
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   private void warnInfoInit(Model model) throws Exception {
/* 171 */     Map<String, Object> params = new HashMap<>();
/* 172 */     params.put("hostname", "主机下线告警");
/* 173 */     int hostDownWarnSize = this.logInfoService.countByParams(params);
/* 174 */     model.addAttribute("hostDownWarnSize", Integer.valueOf(hostDownWarnSize));
/*     */     
/* 176 */     params.clear();
/* 177 */     params.put("hostname", "内存告警");
/* 178 */     int memWarnSize = this.logInfoService.countByParams(params);
/* 179 */     model.addAttribute("memWarnSize", Integer.valueOf(memWarnSize));
/*     */     
/* 181 */     params.clear();
/* 182 */     params.put("hostname", "CPU告警");
/* 183 */     int cpuWarnSize = this.logInfoService.countByParams(params);
/* 184 */     model.addAttribute("cpuWarnSize", Integer.valueOf(cpuWarnSize));
/*     */     
/* 186 */     params.clear();
/* 187 */     params.put("hostname", "带宽告警");
/* 188 */     int netWarnSize = this.logInfoService.countByParams(params);
/* 189 */     model.addAttribute("netWarnSize", Integer.valueOf(netWarnSize));
/*     */     
/* 191 */     params.clear();
/* 192 */     params.put("hostname", "磁盘告警");
/* 193 */     int diskWarnSize = this.logInfoService.countByParams(params);
/* 194 */     model.addAttribute("diskWarnSize", Integer.valueOf(diskWarnSize));
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   private void bytesTop10(Model model) throws Exception {
/* 205 */     Map<String, Object> params = new HashMap<>();
/* 206 */     params.put("orderBy", "CREATE_TIME");
/* 207 */     params.put("orderType", "DESC");
/* 208 */     PageInfo<SystemInfo> pageInfo = this.systemInfoService.selectByParams(params, 1, 10);
/* 209 */     List<String> bytTop10NameList = new ArrayList<>();
/* 210 */     List<String> rxbytTop10List = new ArrayList<>();
/* 211 */     List<String> txbytTop10List = new ArrayList<>();
/* 212 */     for (SystemInfo systemInfo : pageInfo.getList()) {
/* 213 */       bytTop10NameList.add(systemInfo.getHostname());
/* 214 */       rxbytTop10List.add(systemInfo.getRxbyt());
/* 215 */       txbytTop10List.add(systemInfo.getTxbyt());
/*     */     } 
/* 217 */     model.addAttribute("bytTop10NameList", JSONUtil.parseArray(bytTop10NameList));
/* 218 */     model.addAttribute("rxbytTop10List", JSONUtil.parseArray(rxbytTop10List));
/* 219 */     model.addAttribute("txbytTop10List", JSONUtil.parseArray(txbytTop10List));
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   private void setCpuTemperatures(Model model) throws Exception {
/* 229 */     Map<String, Object> params = new HashMap<>();
/* 230 */     List<CpuTemperatures> list = this.cpuTemperaturesService.selectAllByParams(params);
/* 231 */     Double max = Double.valueOf(0.0D);
/* 232 */     String maxIp = "";
/* 233 */     Double avg = Double.valueOf(0.0D);
/* 234 */     Double min = Double.valueOf(1000.0D);
/* 235 */     String minIp = "";
/* 236 */     Double sum = Double.valueOf(0.0D);
/*     */     
/* 238 */     int systemSize = 0;
/*     */     
/* 240 */     for (CpuTemperatures cpuTemperatures : list) {
/* 241 */       Double input = Double.valueOf(cpuTemperatures.getInput());
/* 242 */       if (input == null || input.doubleValue() < 0.0D) {
/*     */         continue;
/*     */       }
/* 245 */       systemSize++;
/* 246 */       if (null != cpuTemperatures.getInput() && Double.valueOf(cpuTemperatures.getInput()).doubleValue() > max.doubleValue()) {
/* 247 */         max = Double.valueOf(cpuTemperatures.getInput());
/* 248 */         maxIp = cpuTemperatures.getHostname();
/*     */       } 
/* 250 */       if (null != cpuTemperatures.getInput() && Double.valueOf(cpuTemperatures.getInput()).doubleValue() < min.doubleValue()) {
/* 251 */         min = Double.valueOf(cpuTemperatures.getInput());
/* 252 */         minIp = cpuTemperatures.getHostname();
/*     */       } 
/* 254 */       if (null != Double.valueOf(cpuTemperatures.getInput())) {
/* 255 */         sum = Double.valueOf(sum.doubleValue() + Double.valueOf(cpuTemperatures.getInput()).doubleValue());
/*     */       }
/*     */     } 
/*     */ 
/*     */     
/* 260 */     if (systemSize > 0) {
/* 261 */       avg = Double.valueOf(sum.doubleValue() / list.size());
/*     */     } else {
/* 263 */       min = Double.valueOf(0.0D);
/*     */     } 
/*     */     
/* 266 */     List<Double> cpuTemperValList = new ArrayList<>();
/* 267 */     cpuTemperValList.add(max);
/* 268 */     cpuTemperValList.add(min);
/* 269 */     cpuTemperValList.add(Double.valueOf(FormatUtil.formatDouble(avg, 2)));
/* 270 */     model.addAttribute("cpuTemperValList", cpuTemperValList);
/* 271 */     model.addAttribute("cpuTemperMaxIp", maxIp);
/* 272 */     model.addAttribute("cpuTemperMinIp", minIp);
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   private void cpuTop10(Model model) throws Exception {
/* 281 */     Map<String, Object> params = new HashMap<>();
/* 282 */     params.put("orderBy", "CREATE_TIME");
/* 283 */     params.put("orderType", "DESC");
/* 284 */     PageInfo<SystemInfo> pageInfo = this.systemInfoService.selectByParams(params, 1, 10);
/* 285 */     List<String> cpuTop10NameList = new ArrayList<>();
/* 286 */     List<Double> cpuTop10ValList = new ArrayList<>();
/* 287 */     for (SystemInfo systemInfo : pageInfo.getList()) {
/* 288 */       cpuTop10NameList.add(systemInfo.getHostname());
/* 289 */       cpuTop10ValList.add(systemInfo.getCpuPer());
/*     */     } 
/* 291 */     model.addAttribute("cpuTop10NameList", JSONUtil.parseArray(cpuTop10NameList));
/* 292 */     model.addAttribute("cpuTop10ValList", JSONUtil.parseArray(cpuTop10ValList));
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   private void memTop10(Model model) throws Exception {
/* 301 */     Map<String, Object> params = new HashMap<>();
/* 302 */     params.put("orderBy", "CREATE_TIME");
/* 303 */     params.put("orderType", "DESC");
/* 304 */     PageInfo<SystemInfo> pageInfo = this.systemInfoService.selectByParams(params, 1, 10);
/* 305 */     List<String> memTop10NameList = new ArrayList<>();
/* 306 */     List<Double> memTop10ValList = new ArrayList<>();
/* 307 */     for (SystemInfo systemInfo : pageInfo.getList()) {
/* 308 */       memTop10NameList.add(systemInfo.getHostname());
/* 309 */       memTop10ValList.add(systemInfo.getMemPer());
/*     */     } 
/* 311 */     model.addAttribute("memTop10NameList", JSONUtil.parseArray(memTop10NameList));
/* 312 */     model.addAttribute("memTop10ValList", JSONUtil.parseArray(memTop10ValList));
/* 313 */     params.clear();
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   private void setMiddleData(List<SystemInfo> systemInfoList, Model model) throws Exception {
/* 325 */     Double maxCpu = Double.valueOf(0.0D);
/* 326 */     Double avgCpu = Double.valueOf(0.0D);
/* 327 */     Double minCpu = Double.valueOf(1000.0D);
/* 328 */     Double sumCpu = Double.valueOf(0.0D);
/*     */     
/* 330 */     Double maxMem = Double.valueOf(0.0D);
/* 331 */     Double minMem = Double.valueOf(1000.0D);
/* 332 */     Double avgMem = Double.valueOf(0.0D);
/* 333 */     Double sumMem = Double.valueOf(0.0D);
/*     */     
/* 335 */     int systemSize = 0;
/* 336 */     int cpuCoresSum = 0;
/* 337 */     double memSum = 0.0D;
/*     */     
/* 339 */     for (SystemInfo systemInfo : systemInfoList) {
/* 340 */       systemSize++;
/* 341 */       if (null != systemInfo.getCpuPer() && systemInfo.getCpuPer().doubleValue() > maxCpu.doubleValue()) {
/* 342 */         maxCpu = systemInfo.getCpuPer();
/*     */       }
/* 344 */       if (null != systemInfo.getCpuPer() && systemInfo.getCpuPer().doubleValue() < minCpu.doubleValue()) {
/* 345 */         minCpu = systemInfo.getCpuPer();
/*     */       }
/* 347 */       if (null != systemInfo.getCpuPer()) {
/* 348 */         sumCpu = Double.valueOf(sumCpu.doubleValue() + systemInfo.getCpuPer().doubleValue());
/*     */       }
/*     */       
/* 351 */       if (null != systemInfo.getMemPer() && systemInfo.getMemPer().doubleValue() > maxMem.doubleValue()) {
/* 352 */         maxMem = systemInfo.getMemPer();
/*     */       }
/* 354 */       if (null != systemInfo.getMemPer() && systemInfo.getMemPer().doubleValue() < minMem.doubleValue()) {
/* 355 */         minMem = systemInfo.getMemPer();
/*     */       }
/* 357 */       if (null != systemInfo.getMemPer()) {
/* 358 */         sumMem = Double.valueOf(sumMem.doubleValue() + systemInfo.getMemPer().doubleValue());
/*     */       }
/*     */       
/*     */       try {
/* 362 */         cpuCoresSum += Integer.valueOf(systemInfo.getCpuCoreNum()).intValue();
/* 363 */       } catch (Exception e) {
/* 364 */         logger.error("统计所有主机总核数错误", e);
/*     */       } 
/*     */       
/*     */       try {
/* 368 */         memSum += Double.valueOf(systemInfo.getTotalMem().replace("G", "")).doubleValue();
/* 369 */       } catch (Exception e) {
/* 370 */         logger.error("统计所有主机总内存错误", e);
/*     */       } 
/*     */     } 
/*     */ 
/*     */     
/* 375 */     if (systemSize > 0) {
/* 376 */       avgCpu = Double.valueOf(sumCpu.doubleValue() / systemInfoList.size());
/* 377 */       avgMem = Double.valueOf(sumMem.doubleValue() / systemInfoList.size());
/*     */     } else {
/* 379 */       minCpu = Double.valueOf(0.0D);
/* 380 */       minMem = Double.valueOf(0.0D);
/*     */     } 
/*     */     
/* 383 */     model.addAttribute("cpuCoresSum", Integer.valueOf(cpuCoresSum));
/* 384 */     model.addAttribute("memSum", FormatUtil.gToT(memSum + ""));
/*     */     
/* 386 */     List<Double> list = new ArrayList<>();
/* 387 */     list.add(maxCpu);
/* 388 */     list.add(Double.valueOf(FormatUtil.formatDouble(avgCpu, 2)));
/* 389 */     list.add(minCpu);
/* 390 */     list.add(maxMem);
/* 391 */     list.add(Double.valueOf(FormatUtil.formatDouble(avgMem, 2)));
/* 392 */     list.add(minMem);
/*     */     
/* 394 */     model.addAttribute("middleDataList", JSONUtil.parseArray(list));
/*     */   }
/*     */ }


/* Location:              /Users/zhangyongxin/soft-install/wgcloud/wgcloud-v3.3.5/server/bank/wgcloud-server-release.jar!/BOOT-INF/classes/com/wgcloud/controller/DapingCotroller.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */